package org.NooLab.texx.storage.db.h2.iciql;

import java.util.ArrayList;

import org.NooLab.itexx.storage.randomwords.iciql.Contexts;
import org.NooLab.utilities.strings.ArrUtilities;



/**
 * 
 * 
 * could be more elegant... via reflection...
 *
 */
public class IciqlHandler {
	
	Contexts c;
	String valueListStr ="";
	ArrayList<Double> valueList = new ArrayList<Double>();
	
	public IciqlHandler( ){
		
	}

	public void clearContext( Contexts c) {
		c.clear();
		valueListStr ="";
		valueList.clear() ;
	}
	
	public Contexts finalizeIciql(){
		
		valueListStr = ArrUtilities.arr2Text(valueList , 7, ";") ;
		c.randomcontext = valueListStr ;
		return c;
	}

	/*
	 	 frequency, , 
	 */
	public void setContextArgument( String colname, String strval) {
		if (colname.contentEquals("word")){           c.wordlabel = strval ;}
		if (colname.contentEquals("storLabelGuid")){       ;}
		if (colname.contentEquals("reserved_01")){         ;}
		if (colname.contentEquals("version")){        c.version = strval ;}
		if (colname.contains("compoundlabel")){       c.compoundlabel = strval ;}
		if (colname.contains("storelabel")){          c.storlabel = strval ;}
		if (colname.contentEquals("language")){       c.language = strval ;}
	}

	public void setContextArgument( String colname, long index) {
		
		if (colname.contentEquals("index")){    c.contextid = index;}
		if (colname.contentEquals("docindex")){ c.docid = index ;}
		if (colname.contentEquals("fpindex")){  c.fpindex = index ;}
		if (colname.contentEquals("storindex")){ ;}
		if (colname.contentEquals("entityid")){ c.entityid = index;}
		if (colname.contentEquals("")){         ;}
	}
	public void setContextArgument( String colname, int val) {

		if (colname.contentEquals("frequency")){    c.frequency = val ;}
		if (colname.contentEquals("groupsCount")){  c.groupsCount = val ;}
		if (colname.contentEquals("status")){       c.status = val ;}
		if (colname.contentEquals("entitytype")){   c.entitytype = val ;}
		if (colname.contentEquals("varianttype")){  c.varianttype = val ;} 
	}
	
	
	public void setContextArgument( String colname, double numval) {

		try{
			
			if (colname.contentEquals("distanceMean")){  c.distanceMean = numval ;}
			if (colname.contentEquals("distanceStDev")){ c.distanceStDev = numval ;}
			if (colname.contentEquals("saliency")){      c.saliency = numval ;}
			if (colname.contentEquals("")){      ;}
			if (colname.contentEquals("")){      ;}
			if (colname.contentEquals("")){      ;}  

			if (colname.contentEquals("frequency")){    c.frequency = (int) Math.round(numval) ;}
			if (colname.contentEquals("groupsCount")){  c.groupsCount = (int) Math.round(numval) ;}
			if (colname.contentEquals("status")){       c.status = (int) Math.round(numval) ;}
			if (colname.contentEquals("entitytype")){   c.entitytype = (int) Math.round(numval) ;}
			if (colname.contentEquals("varianttype")){  c.varianttype = (int) Math.round(numval) ;} 

		}catch(Exception e){
			
			int ival = (int) Math.round(numval) ;
			setContextArgument( colname, ival) ;
		}

	}

	public void setContextProfileValue( int cix, int vcix, double numval) {
		valueList.add(numval) ;
	}

	
	public void setContextsObj(Contexts ctxt) {
 
		c = ctxt ;
	}

	
	
	
}
